gtk-demo: Make CSS a resource
authorBenjamin Otte <otte@redhat.com>
Sun, 13 May 2012 19:23:41 +0000 (21:23 +0200)
committerCosimo Cecchi <cosimoc@gnome.org>
Wed, 30 May 2012 17:17:22 +0000 (13:17 -0400)
Also, improve the CSS to give you that basic feel.

demos/gtk-demo/Makefile.am
demos/gtk-demo/css_basics.c
demos/gtk-demo/css_basics.css [new file with mode: 0644]
demos/gtk-demo/demo.gresource.xml
demos/gtk-demo/reset.css [new file with mode: 0644]
demos/gtk-demo/theming_custom_css.c
demos/gtk-demo/theming_style_classes.c

index 71a0f859aef7e00cc01815227650c3db7b96c2b3..7ef52f710916fe9e53bc064fef0f78a207bca0e2 100644 (file)
@@ -76,13 +76,8 @@ BUILT_SOURCES = demos.h demo_resources.c
 EXTRA_DIST +=                          \
        $(IMAGEFILES)                   \
        demo.ui                         \
-       demo.gresource.xml      \
-       application.ui                  \
-       menus.ui                        \
-       theming.ui                      \
-       fancy.css                       \
-       gtk-logo-24.png                 \
-       gtk-logo-48.png                 \
+       demo.gresource.xml              \
+       $(RESOURCES)                    \
        org.gtk.Demo.gschema.xml
 
 gsettings_SCHEMAS = \
@@ -110,9 +105,18 @@ gtk3_demo_application_SOURCES = \
 
 gtk3_demo_application_LDADD = $(LDADDS)
 
-demo_resources.c: demo.gresource.xml gtk-logo-24.png gtk-logo-48.png application.ui menus.ui
+demo_resources.c: demo.gresource.xml $(RESOURCES)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $(srcdir)/demo.gresource.xml
 
+RESOURCES=     application.ui                  \
+               menus.ui                        \
+               theming.ui                      \
+               gtk-logo-24.png                 \
+               gtk-logo-48.png                 \
+               css_basics.css                  \
+               fancy.css                       \
+               reset.css
+
 IMAGEFILES=    alphatest.png           \
                apple-red.png           \
                background.jpg          \
@@ -131,11 +135,8 @@ IMAGEFILES=        alphatest.png           \
 democode_DATA = \
        $(demos)                \
        $(IMAGEFILES)           \
-       demo.ui                 \
-       menus.ui                \
-       application.ui          \
-       theming.ui              \
-       fancy.css
+       $(RESOURCES)            \
+       demo.ui
 
 DISTCLEANFILES = demos.h
 
index 0cbabbe48767c794b8900ff57dd8e0e4aa0492a5..3eb5e3bb6a98c897d9d0c4a7475fbc09f0584779 100644 (file)
@@ -9,20 +9,6 @@
 
 static GtkWidget *window = NULL;
 
-#define DEFAULT_CSS \
-  "/* You can edit the CSS to change the appearance of this Window */\n" \
-  "\n" \
-  "GtkWindow {\n" \
-  "  engine: none;\n" \
-  "  background-image: none;\n" \
-  "  background-color: brown;\n" \
-  "}\n" \
-  "\n" \
-  "GtkTextView {\n" \
-  "  color: green;\n" \
-  "}\n" \
-  "\n"
-
 static void
 show_parsing_error (GtkCssProvider *provider,
                     GtkCssSection  *section,
@@ -83,6 +69,7 @@ do_css_basics (GtkWidget *do_widget)
       GtkWidget *container, *child;
       GtkStyleProvider *provider;
       GtkTextBuffer *text;
+      GBytes *bytes;
       
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget));
@@ -110,9 +97,10 @@ do_css_basics (GtkWidget *do_widget)
                         "changed",
                         G_CALLBACK (css_text_changed),
                         provider);
-      gtk_text_buffer_set_text (text,
-                                DEFAULT_CSS,
-                                -1);
+
+      bytes = g_resources_lookup_data ("/css_basics/gtk.css", 0, NULL);
+      gtk_text_buffer_set_text (text, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
+
       g_signal_connect (provider,
                         "parsing-error",
                         G_CALLBACK (show_parsing_error),
diff --git a/demos/gtk-demo/css_basics.css b/demos/gtk-demo/css_basics.css
new file mode 100644 (file)
index 0000000..bd6a694
--- /dev/null
@@ -0,0 +1,22 @@
+/* You can edit the text in this window to change the
+ * appearance of this Window.
+ * Be careful, if you screw it up, nothing might be visible
+ * anymore. :)
+ */
+
+/* This CSS resets all properties to their defaults values
+ *    and overrides all user settings and the theme in use */
+@import url("reset.css");
+
+/* Set a very futuristic style by default */
+* {
+  color: green;
+  font-family: Monospace;
+  border: 1px solid;
+}
+
+/* Make sure selections are visible */
+:selected {
+  background-color: darkGreen;
+  color: black;
+}
index d4a5aeca164a5b0395e1c6b658107f1d6fa6dd17..67aeff4f1ba91c4453433e57eb21877280fa7d83 100644 (file)
@@ -8,4 +8,16 @@
     <file preprocess="xml-stripblanks">application.ui</file>
     <file preprocess="xml-stripblanks">menus.ui</file>
   </gresource>
+  <gresource prefix="/">
+    <file>reset.css</file>
+  </gresource>
+  <gresource prefix="/css_basics">
+    <file alias="gtk.css">css_basics.css</file>
+  </gresource>
+  <gresource prefix="/theming_custom_css">
+    <file alias="gtk.css">fancy.css</file>
+  </gresource>
+  <gresource prefix="/theming_style_classes">
+    <file preprocess="xml-stripblanks">theming.ui</file>
+  </gresource>
 </gresources>
diff --git a/demos/gtk-demo/reset.css b/demos/gtk-demo/reset.css
new file mode 100644 (file)
index 0000000..1c27a8e
--- /dev/null
@@ -0,0 +1,68 @@
+/* @import this colorsheet to get the default values for every property.
+ * This is useful when writing special CSS tests that should not be
+ * inluenced by themes - not even the default ones.
+ * Keep in mind that the output will be very ugly and not look like
+ * anything GTK.
+ * Also, when adding new style properties, please add them here.
+ */
+
+* {
+  color: inherit;
+  font-size: inherit;
+  background-color: initial;
+  font-family: inherit;
+  font-style: inherit;
+  font-variant: inherit;
+  font-weight: inherit;
+  text-shadow: inherit;
+  icon-shadow: inherit;
+  box-shadow: initial;
+  margin-top: initial;
+  margin-left: initial;
+  margin-bottom: initial;
+  margin-right: initial;
+  padding-top: initial;
+  padding-left: initial;
+  padding-bottom: initial;
+  padding-right: initial;
+  border-top-style: initial;
+  border-top-width: initial;
+  border-left-style: initial;
+  border-left-width: initial;
+  border-bottom-style: initial;
+  border-bottom-width: initial;
+  border-right-style: initial;
+  border-right-width: initial;
+  border-top-left-radius: initial;
+  border-top-right-radius: initial;
+  border-bottom-right-radius: initial;
+  border-bottom-left-radius: initial;
+  outline-style: initial;
+  outline-width: initial;
+  outline-offset: initial;
+  background-clip: initial;
+  background-origin: initial;
+  background-size: initial;
+  background-position: initial;
+  border-top-color: initial;
+  border-right-color: initial;
+  border-bottom-color: initial;
+  border-left-color: initial;
+  outline-color:  initial;
+  background-repeat: initial;
+  background-image: initial;
+  border-image-source: initial;
+  border-image-repeat: initial;
+  border-image-slice: initial;
+  border-image-width: initial;
+  transition-property: initial;
+  transition-duration: initial;
+  transition-timing-function: initial;
+  transition-delay: initial;
+  engine: initial;
+  gtk-key-bindings: initial;
+
+  -GtkWidget-focus-line-width: 0;
+  -GtkWidget-focus-padding: 0;
+  -GtkNotebook-initial-gap: 0;
+}
index 00cb22ac328a892a325defd1e0d70d9ca72ce382..a1b9aeafa8544d0caad814e058f9bb72e09e8d8c 100644 (file)
@@ -20,7 +20,7 @@ do_theming_custom_css (GtkWidget *do_widget)
   GtkWidget *box;
   GtkWidget *button;
   GtkCssProvider *provider;
-  gchar *filename;
+  GBytes *bytes;
 
   if (!window)
     {
@@ -40,13 +40,14 @@ do_theming_custom_css (GtkWidget *do_widget)
       gtk_widget_set_name (button, "fancy");
 
       provider = gtk_css_provider_new ();
-      filename = demo_find_file ("fancy.css", NULL);
-      gtk_css_provider_load_from_path (provider, filename, NULL);
+      bytes = g_resources_lookup_data ("/theming_custom_css/gtk.css", 0, NULL);
+      gtk_css_provider_load_from_data (provider, g_bytes_get_data (bytes, NULL),
+                                       g_bytes_get_size (bytes), NULL);
       gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (do_widget),
                                                  GTK_STYLE_PROVIDER (provider),
                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
       g_object_unref (provider);
-      g_free (filename);
+      g_bytes_unref (bytes);
 
       gtk_widget_show_all (box);
     }
index 4377e2dabbe9eb34cb60d0bca3d87aa5aac4f971..d089ece8b1d5b9c1056ea5dea668fba61ff4705b 100644 (file)
@@ -18,7 +18,6 @@ do_theming_style_classes (GtkWidget *do_widget)
 {
   GtkWidget *grid;
   GtkBuilder *builder;
-  gchar *filename;
   GError *err = NULL;
 
   if (!window)
@@ -32,9 +31,7 @@ do_theming_style_classes (GtkWidget *do_widget)
                         G_CALLBACK (gtk_widget_destroyed), &window);
 
       builder = gtk_builder_new ();
-      filename = demo_find_file ("theming.ui", NULL);
-      gtk_builder_add_from_file (builder, filename, &err);
-      g_free (filename);
+      gtk_builder_add_from_resource (builder, "/theming_style_classes/theming.ui", NULL);
       if (err)
         {
           g_error ("ERROR: %s\n", err->message);